/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.threads.stack;

import java.util.logging.Logger;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.threads.stack
 * @author:LiBo/Alex
 * @create-date:2020-05-11 11:50
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class StackTraceUtils {

    static Logger logger = Logger.getLogger(StackTraceUtils.class.getName());

    /** 在LogCat中输出提示信息info,并给出输出该信息在代码中的完整调用树 */
    public static void messageWithSrcTree()
    {
        //从当前位置，获取代码调用堆栈
        StackTraceElement[] elem = Thread.currentThread().getStackTrace();
        for(StackTraceElement e : elem)
        {
            String str = e.getFileName() + " " + e.getLineNumber() + "行：" + e.getClassName() + " -> "  + e.getMethodName() + "()" ;
            //输出调用位置信息
            //logger.info(str);
//	    	Log.e(info, str);
			System.out.println("堆栈输出:" + "  " + str);
        }
    }

    // 当try块出错时，给出当前代码位置的，出错提示信息
    // try{...}catch(Exception e){ Tools.MessageWithSrcSite("执行try{}时出错！"); }
    public static void main(String[] args){
        messageWithSrcTree();
    }
}
